<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>找到小镇的法官</title>
</head>
<body>
  <script>
    function fn(n, trust) {
      let nums = new Array(n + 1).fill(0)
      let res = new Array(n + 1).fill(0)
      for (let i of trust) {
        nums[i[1]]++
        res[i[0]]++
      }
      for (let i = 1; i <= n; i++)
        if (res[i] == 0 && nums[i] == n - 1)
          return i
      return -1
    }
    console.log(fn(2, [[1, 2]]))
  </script>
</body>
</html>